package com.huitone.gddw.utils;

import java.util.HashMap;

import javax.servlet.http.HttpSession;

/**
 * session类
 * @author wuluodan
 *
 */
public class SessionContext {

	private static SessionContext instance;  
    private HashMap<String, HttpSession> sessionMap;  
   
    private SessionContext() {  
        sessionMap = new HashMap<String,HttpSession>();  
    }  
  
    public static SessionContext getInstance() {  
        if (instance == null) {  
            instance = new SessionContext();  
        }  
        return instance;  
    }  
  
    public synchronized void AddSession(HttpSession session) {  
        if (session != null) {  
            sessionMap.put(session.getId(), session);  
        }  
    }  
  
    public synchronized void DelSession(HttpSession session) {  
        if (session != null) {  
            sessionMap.remove(session.getId());  
            if (session.getAttribute("userId") != null) {  
                sessionMap.remove(session.getAttribute("userId").toString());  
                session.invalidate(); // 强行退出
            }  
        }  
    }  
  
    public synchronized HttpSession getSession(String sessionId) {  
        if (sessionId == null) return null;  
        return (HttpSession)sessionMap.get(sessionId);  
    }  
  
    public HashMap<String, HttpSession> getSessionMap() {  
        return sessionMap;  
    }  
  
    public void setMymap(HashMap<String, HttpSession> sessionMap) {  
        this.sessionMap = sessionMap;  
    } 
	
}
